package com.servlet;

import com.entity.DinerComment;
import com.entity.dto.LayuiPage;
import com.service.DinerCommentService;
import com.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping
@CrossOrigin
public class DinerCommentServlet {

    @Autowired
    DinerCommentService service;


    @RequestMapping("getComment")
    public LayuiPage<DinerComment> getListComment(Integer score) {
        LayuiPage<DinerComment> layuiPage = new LayuiPage<>();
        layuiPage.setType("Array");
        layuiPage.setMsg("ok");
        layuiPage.setData(service.getListComment(score));
        return layuiPage;
    }

    @RequestMapping(value = "addCommentInfo")
    public LayuiPage<Integer> addCommentInfo(DinerComment comment, HttpServletRequest request) {
        LayuiPage<Integer> layuiPage = new LayuiPage<>();
        comment.setUser_id(UserUtil.getUserId(request));
        if (service.addCommentInfo(comment) == 0) {
            layuiPage.setCode(201);
            layuiPage.setMsg("添加失败");
        }else {
            layuiPage.setMsg("ok");
        }
        layuiPage.setType("Integer");
        layuiPage.setData(null);
        return layuiPage;
    }


}
